package com.jml.rabbitmq;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;


public class RabbitMQConnection {

    /**
     * 创建连接
     */
    public static Connection getConnection() throws IOException, TimeoutException {
        //1.创建connectionFactory
        ConnectionFactory connectionFactory = new ConnectionFactory();
        //2.配置Host
        connectionFactory.setHost("172.26.3.145");
        //3.设置Port
        connectionFactory.setPort(5672);
        //4.设置账户和密码
        connectionFactory.setUsername("jml");
        connectionFactory.setPassword("1234");
        //5.设置VirtualHost
        connectionFactory.setVirtualHost("/");
        return connectionFactory.newConnection();
    }
}
